from flask import Flask
from config import Config
from extensions import db, migrate
from routes import api
from flask_cors import CORS

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)
    CORS(app)  # 默认允许所有域名访问所有路由

    # Initialize extensions
    db.init_app(app)
    migrate.init_app(app, db)
    with app.app_context():
        db.create_all()  # 创建所有定义的表

    # Register blueprints
    app.register_blueprint(api, url_prefix='/api')

    return app


